#include<bits/stdc++.h>
using namespace std;
inline long long quick_mod(long long b,long long p,long long mod) {
	register long long tmp=b;
    register long long ans=1;
	while(p!=0){
		if(p%2!=0){
			ans=(1ll*ans%mod
                *1ll*tmp%mod)
                %mod;
        }
		tmp=(1ll*tmp%mod
            *1ll*tmp%mod)
            %mod;
		
        p/=2;
	}
	return ans%mod;
}
inline long long read(){
	long long x;
	scanf("%lld",&x);
	return x;
}
long long IN() {
	char ch;
	long long a=0;
	while((ch=getchar())==' '||ch=='\n')
		a+=ch-'0';
	while((ch=getchar())!=' '&&ch!='\n') {
		a*=10;
		a+=ch-'0';
	}
	return a;
}
inline long long check(long long a){
    int ans=1,i=1;
    for(int i=a;i>1;i--){
        if(a%i==0){
            ans++;
            a/=i;
            i=a;
        }
    }
    return ans+1;
}
int main() {
	long long p,e,i,d;
	long long time=1;
	while((p=read())+(e=read())+(i=read())+(d=read())==-4,time++) {
		// if((p=read())+(e=read())+(i=read())+(d=read())==-4){
		// 	return 0;
		// }
		for(int j=1+d; j<=21252; j++) {
			if((abs(j-p)%23+abs(j-e)%28+abs(j-i)%33)==0) {
				printf("Case %lld: the next triple peak occurs in %lld days.\n",time-1,abs(j-d));
				break;
			}
		}
	}
}